package utils

import (
	"crypto/md5"
	"encoding/hex"
	"math/rand"
	"strconv"
	"time"
)

func GenerateToken(userId int64) string {
	return strconv.FormatInt(userId, 10) + strconv.FormatInt(time.Now().Unix(), 10) + GenerateRandomNumberInRange(1000, 9999)
}

func GetRefreshToken(token string) string {
	return "r_" + token
}

func GenerateRandomNumberInRange(min, max int) string {
	num := rand.Intn(max-min+1) + min
	return strconv.Itoa(num)
}

func Md5(str string) string {
	hash := md5.Sum([]byte(str))
	return hex.EncodeToString(hash[:])
}
